import time

from common.shopping import shopping


class register:
    def __init__(self):
        self.lg=shopping()
        # self.lg.QT_login("123@qq.com","123456")

    def QT_user(self,li):
        newstepli=[]
        stepli=li[4].split("\n")
        for i in stepli:
            newstepli.append(i.split("=")[1])
        wd=self.lg.QT_register(newstepli)
        result=self.jude(wd,li[-1])
        re=""
        if result:
            re="%s pass"%li[0]
            print("%s pass"%li[0])
        else:
            re="%s failed"%li[0]
            print("%s failed"%li[0])

        with open("../TestReport/GUI测试报告.xls","a+") as f:
            f.writelines(re+"\n")


    def jude(self,wd,exp):
        result=True
        try:
            warn=wd.find_element_by_class_name("invalid-msg").text
            if exp in warn:
                print("不填写其中一个参数：注册失败")
            else:
                print("不填写其中一个参数：注册成功")
            time.sleep(2)

        except:
            str=wd.find_element_by_xpath("/html/body/div[2]/div/div[1]/span").text
            if exp in str:
                print("所有字段均填写成功：注册成功")
            else:
                print("所有字段均填写成功：注册失败")
        return result


    ##